<?php
namespace ctrl\demo;

use Sdk\Plglobal\callPlglobalApiUtil;

class plglobal
{
    //刷新token http://ec.com/?c=demo_plglobal&a=token
    public static function token()
    {
        \serv\task\warehouse\plglobal::token();
    }

    //获取仓库列表 http://ec.com/?c=demo_plglobal&a=warehouseList
    public static function warehouseList()
    {
        $action = '/3plapi/openapi/getWarehouses';
        $data = [];
        $result = callPlglobalApiUtil::callPlglobalApi($action, 'GET', $data);
        $star = 192;
        foreach ($result['data'] as $k => $v) {
            $id = $star + $k;
            $warehouseName = addslashes($v['warehouseCode']);
            $sql = "INSERT INTO warehouse(warehouse_id, `name`, `name_en`, warehouse_code, country, province, city, address, postcode, warehouse_region, `type`) 
                        VALUES ('{$id}', '{$warehouseName}', '{$warehouseName}', '{$v['warehouseCode']}', '{$v['countryCode']}', '', '', '', '', '{$v['countryCode']}', 110);";
            echo $sql;
            echo '<br />';
        }
    }

    //拉取库存数据 http://ec.com/?c=demo_plglobal&a=pull
    public static function pull()
    {
        \serv\task\warehouse\plglobal::pull();
    }

    //拉取库存数据 http://ec.com/?c=demo_plglobal&a=pullQueue
    public static function pullQueue()
    {
        $string = '{"warehouse_id":"194","warehouse_code":"CA2","warehouse":{"NJ1":"192","NJ2":"193","CA2":"194","CA3":"195","AT1":"196","NJ3":"197","AT2":"198","CA4":"199","NJ4":"200","ATX4":"201","TX1":"202","CA5":"203","AT3":"204","CAX2":"205","NJX1":"206","CAX3":"207","NJX2":"208","NJX3":"209","TXX1":"210","AT4":"211","CA6":"212","CA7":"213","CAX6":"214","ATX5":"215","CAN1":"216","CAN2":"217","NJX4":"218","ATN1":"219","ATX6":"220","CA8":"221","CAN3":"222","CAX7":"223","NJX5":"224","CAX8":"225","CA9":"226","AT5":"227","TXX2":"228","CA10":"229","CAN5":"230","CA11":"231"}}';
        $data['data'] = json_decode($string, true);
        $result = \serv\queue\warehouse\plglobal::pull($data);
        var_dump($result);
    }

    //更新或锁 //http://ec.com/?c=demo_plglobal&a=stock
    public static function stock()
    {
        $string = '{"customerSkuCode":["C0001042A-Clear-Black"],"systemSku":"D381094248","warehouseCode":"NJ4","inStockQty":12,"availableStockQty":12,"inUsedStockQty":0,"transferOnWayStockQty":0,"warehouse_id":"200"}';
        $data['data'] = json_decode($string, true);
        $result = \serv\queue\warehouse\plglobal::check($data);
        var_dump($result);
    }

}


